<template>
  <div class="warp">
    <div>
      <div class="title">登录</div>
      <div class="login-group">
        <div class="login-group-item">
          <div class="login-label">用户名</div>
          <div>
            <input v-model="form.userName" type="text" placeholder="用户名" />
          </div>
        </div>
        <div class="login-group-item">
          <div class="login-label">密码</div>
          <div class="login-input">
            <input v-model="form.password" type="password" placeholder="密码" />
          </div>
        </div>
        <div class="login-group-btn">
          <div class="btn" @click="login">登录</div>
        </div>
      </div>
    </div>
  </div>
</template>

<script lang="ts" setup>
  import { useUserStore } from '@/store/modules/user'
  import { ref } from 'vue'
  import { useRouter } from 'vue-router'
  const router = useRouter()
  const _useUserStore = useUserStore()
  const form = ref({
    userName: '',
    password: '',
  })
  const login = (e) => {
    _useUserStore
      .login(form.value.userName, form.value.password)
      .then((result) => {
        if (result.code === 200) {
          router.push({
            path: '/list',
          })
        }
      })
      .catch((err) => {})
  }
</script>
<style lang="scss" scoped>
  .warp {
    height: 100vh;
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    .title {
      text-align: center;
      font-size: 24px;
      line-height: 50px;
      font-weight: bold;
    }
    .login-group {
      background: #ffffff;
      border-radius: 5px;
      padding: 45px 30px 0px;
      box-shadow: 0px 6px 10px rgba(144, 147, 153, 0.5);
      margin: auto;
      width: 80%;
      height: 240px;
      position: relative;
      .login-group-item {
        height: 50px;
        font-size: 16px;
        display: flex;
        .login-label {
          width: 80px;
        }
        .login-input {
        }
      }
      .login-group-btn {
        width: calc(100% - 60px);
        position: absolute;
        bottom: 20px;
        text-align: center;
        display: flex;
        justify-content: center;
        .btn {
          line-height: 28px;
          height: 30px;
          width: 90px;
          border-radius: 3px;
          border: 1px #dedfe0 solid;
        }
      }
    }
  }
</style>
